<template>
	<view class="content">
		<view class="top">
			<view class="top2">
				<input :focus="true" type="text" @confirm="sousuo" @input="key" confirm-type="search" placeholder="请输入师傅编号或师傅名称查找">
			</view>
			<view class="top3" @click="sou">搜索</view>
		</view>
		
		<!--<view class="fenxian hg3"></view>
		<view :class="is_pf==0?'top22':'top222'">
			<picker class="top33" @change="pai" :value="px_index" :range="paixu">
				<view class="top4">
					<text>{{paixu[px_index]}}</text>
					<image src="../../static/images/xia.png" mode="aspectFit"></image>
				</view>
			</picker>
			<picker class="top33" @change="xingbie" :value="sex_index" :range="sex">
				<view class="top4">
					<text v-if="sex_index==0">老师性别</text>
					<text v-if="sex_index>0">{{sex[sex_index]}}</text>
					<image src="../../static/images/xia.png" mode="aspectFit"></image>
				</view>
			</picker>
			<picker class="top33" @change="jiguan" :value="sheng_index" :range="sheng">
				<view class="top4">
					<text v-if="sheng_index==0">老师籍贯</text>
					<text v-if="sheng_index>0">{{sheng[sheng_index]}}</text>
					<image src="../../static/images/xia.png" mode="aspectFit"></image>
				</view>
			</picker>
			<picker class="top33" @change="yuanxiao" :value="school_index" :range="school.types">
				<view class="top4">
					<text v-if="school_index==0">院校经验</text>
					<text v-if="school_index>0">{{school.types[school_index]}}</text>
					<image src="../../static/images/xia.png" mode="aspectFit"></image>
				</view>
			</picker>
			<view class="top33" @click="xshaixuan" data-type="3">
				<view class="top4">
					<text>学科筛选</text>
					<image src="../../static/images/xia.png" mode="aspectFit"></image>
				</view>
			</view>
		</view>-->
		<view class="goods">
			<view class="goods3">
				<view class="goods4" v-for="(g,index) in goods">
					<view class="goods4-0">
						<image @click="gurl" :data-id="g.id" class="goods4-1" :src="g.avatar" mode="aspectFit"></image>
						<view class="goods4-2">
							<view class="goods4-3">
								<view @click="gurl" :data-id="g.id" class="goods4-3-1">T{{g.id}}-{{g.nickname}}</view>
								<image @click="jubao" :data-index="index" class="map4" src="../../static/images/dian.png" mode="aspectFit"></image>
							</view>
							<view class="goods44" @click="gurl" :data-id="g.id">
								<view class="goods4-7">{{g.cate}}</view>
								<view class="goods4-4">距您{{g.juli}}km</view>
							</view>
							<view @click="gurl" :data-id="g.id" class="goods5"><text v-if="g.is_real==1">{{g.px_year}}年培训经验</text></view>
							<view @click="gurl" :data-id="g.id" class="goods6"><text v-if="g.is_real==1">{{g.is_zx==1?'在读':'毕业'}}于{{g.school}}</text></view>
						</view>
					</view>
					<view class="map" @click="gurl" :data-id="g.id">
						<image class="map3" src="../../static/images/map2.png" mode="aspectFit"></image>
						<view class="map2">{{g.address}}</view>
						
					</view>
				</view>
			</view>
			
		</view>
		<image class="empty" v-if="!goods[0] && is_ss==1" src="../../static/images/empty.png" mode="widthFix"></image>
		<view style="width:100%;height:5px;"></view>
		
		<view class="zheceng" v-if="is_xk==true" @click="xshaixuan"></view>
		<view class="zheceng2" v-if="is_xk==true">
			<view class="zheceng3">学科筛选</view>
			<view class="zheceng4">
				<view class="zheceng4-1">一级学科</view>
				<view class="zheceng4-2">
					<view @click="lei" data-id="0" :class="cid==0?'zheceng4-2-1 zcactive':'zheceng4-2-1'">不限</view>
					<view @click="lei" data-type="1" :data-index="index" :data-id="c.id" :class="cid==c.id?'zheceng4-2-1 zcactive':'zheceng4-2-1'" v-for="(c,index) in xueke">{{c.title}}</view>
				</view>
			</view>
			<view class="zheceng4" v-if="cid>0">
				<view class="zheceng4-1">二级学科</view>
				<view class="zheceng4-2">
					<view @click="lei2" data-id="0" :class="cid2==0?'zheceng4-2-1 zcactive':'zheceng4-2-1'">不限</view>
					<view @click="lei2" :data-id="c.id" :class="cid2==c.id?'zheceng4-2-1 zcactive':'zheceng4-2-1'" v-for="c in xueke2">{{c.title}}</view>
				</view>
			</view>
			<view class="zheceng5" @click="xshaixuan">关闭</view>
		</view>
		<view class="gaodu"></view>
		<view class="zheceng" v-if="is_jb==true" @click="jbclose"></view>
		<view class="jubaocause" v-if="is_jb==true">
			<view class="jubaocause2">
				<text>举报原因</text>
				<image src="../../static/cha.png" mode="aspectFit" @click="jbclose"></image>
			</view>
			<view class="jubaocause3">
				<textarea @input="cause" placeholder="请填写举报原因"></textarea>
			</view>
			<view class="jubaocause4">
				<view class="jubaocause4-1" @click="jbclose">取消</view>
				<view class="jubaocause4-2" @click="bao">提交</view>
			</view>
		</view>
	</view>
	
</template>

<script>
	var app=getApp();
	export default {
		data() {
			return {
				height: 0,
				is_pf:0,
				show:0,
				keyword:'',
				keyword2:'',
				advert:[],
				news:[],
				school:[],
				school_index:0,
				xueke:[],
				xueke2:[],
				sheng:[],
				sheng_index:0,
				site:[],
				goods:[],
				paixu:['距离最近','编号排序','人气最高','评价最好','精选老师','距离最远'],
				px_index:0,
				sex:['不限','男老师','女老师'],
				sex_index:0,
				is_xk:false,
				is_jb:false,
				yuanyin:'',
				zt_id:0,
				jb_index:0,
				lng:0,
				lat:0,
				cid:0,
				cid2:-1,
				page:1,
				next:0,
				is_ss:0
			}
		},
		onLoad() {
			uni.getLocation({
			    type: 'gcj02',
			    success: function (res) {
					that.lng=res.longitude;
					that.lat=res.latitude;
			    },
				fail(e){
					uni.getLocation({
					    type: 'gcj02',
					    success: function (res) {
							that.lng=res.longitude;
							that.lat=res.latitude;
					    },
						fail(e){
							
						}
					});
				}
			});
		},
		methods: {
			getdata(){
				var that=this;
				uni.showLoading({
				    title: '数据加载中'
				});
				
				uni.request({
				    url: app.globalData.url+"index/index",
					method:"POST",
					dataType:"json",
					header: {
					    'content-type': 'application/x-www-form-urlencoded'
					},
				    data: {},
				    success: (res) => {
						uni.hideLoading();
						that.news=res.data.data.news
						that.advert=res.data.data.advert
						that.xueke=res.data.data.xueke;
						that.sheng=res.data.data.sheng;
						that.school=res.data.data.school;
						that.site=res.data.data.site;
						that.show=1;
						uni.setNavigationBarTitle({
						    title: res.data.data.site.title
						});
						uni.showLoading({
						    title: '数据加载中'
						});
						that.laoshi(0,1);return false;
						uni.getLocation({
						    type: 'gcj02',
						    success: function (res) {
								that.lng=res.longitude;
								that.lat=res.latitude;
								that.laoshi(0,1);
						    },
							fail(e){
								uni.getLocation({
								    type: 'gcj02',
								    success: function (res) {
										console.log(res);
										that.lng=res.longitude;
										that.lat=res.latitude;
										that.laoshi(0,1);
								    },
									fail(e){
										that.laoshi(0,1);
									}
								});
							}
						});
						
				    }
				});
			},
			laoshi(t=0,tt=0){
				var that=this;
				if(tt==0){
				uni.showLoading({
				    title: '数据加载中'
				});
				}
				var s=0;
				var j=0;
				if(this.school_index>0){
					
					if(this.school_index<=this.school.school_count){
						var t2=this.school_index-1;
						s=this.school.type[t2].id;
					}else{
						var t2=this.school_index-1-this.school.school_count;
						j=this.school.jingyan[t2].id;
					}
					
				}
				var uid = uni.getStorageSync('uid');
				if(app.isBlank(uid)==true){
					uid=0;
				}
				uni.request({
				    url: app.globalData.url+"teacher/index",
					method:"POST",
					dataType:"json",
					header: {
					    'content-type': 'application/x-www-form-urlencoded'
					},
				    data: {uid:uid,page:that.page,px:that.px_index,sex:that.sex_index,school:s,jingyan:j,cid:that.cid,cid2:that.cid2,keyword:that.keyword2,lng:that.lng,lat:that.lat},
				    success: (res) => {
						uni.hideLoading();
						if(t==1){
							that.goods=res.data.data.teacher
						}else{
							that.goods=that.goods.concat(res.data.data.teacher)
						}
						that.xueke2=res.data.data.cate2
						that.is_ss=1;
						that.keyword2=that.keyword;
						that.next=res.data.data.next
				    }
				});
			},
			jubao(e){
				const uid = uni.getStorageSync('uid');
				if(app.isBlank(uid)==true){
					uni.showModal({
					    content: '请登录后操作',
						confirmText:'去登录',
					    success: function (res) {
					        if (res.confirm) {
					            uni.navigateTo({
					                url: '/pages/login/login'
					            });
					        }
					    }
					});
					return false;
				}
				this.jb_index=e.currentTarget.dataset.index;
				var that=this;
				uni.showActionSheet({
				    itemList: ['举报', '拉黑'],
				    success: function (res) {
						if(res.tapIndex==0){
							that.is_jb=true;
						}else{
							uni.showModal({
							    title: '确定要拉黑该老师吗？',
							    content: '拉黑后，将不会再对您展示该老师',
							    success: function (res2) {
							        if (res2.confirm) {
							            that.lahei();
							        } else if (res.cancel) {
							            console.log('用户点击取消');
							        }
							    }
							});
							
						}
				    },
				    fail: function (res) {
				        console.log(res.errMsg);
				    }
				});
			},
			lahei(){
				var that=this;
				uni.showLoading({
				    title: '请求中..'
				});
				const uid = uni.getStorageSync('uid');
				uni.request({
				    url: app.globalData.url+"index/lahei",
					method:"POST",
					dataType:"json",
					header: {
					    'content-type': 'application/x-www-form-urlencoded'
					},
				    data: {uid:uid,id:that.goods[that.jb_index].id,type:1},
				    success: (res) => {
						uni.hideLoading();
						if(res.data.code!=1){
							uni.showToast({
							    title: res.data.msg,
								icon:'none',
							    duration: 1500
							});
							return false;
						}
						that.goods.splice(that.jb_index,1);
						uni.showToast({
						    title: res.data.msg,
							icon:'success',
						    duration: 1500
						});
				    }
				});
			},
			jbclose(){
				this.yuanyin='';
				this.is_jb=false;
			},
			bao(){
				var that=this;
				if(app.isBlank(this.yuanyin)==true){
					uni.showToast({
					    title: "请填写举报原因",
						icon:'none',
					    duration: 1000
					});
					return false;
				}
				uni.showLoading({
				    title: '请求中..'
				});
				const uid = uni.getStorageSync('uid');
				uni.request({
				    url: app.globalData.url+"index/jubao",
					method:"POST",
					dataType:"json",
					header: {
					    'content-type': 'application/x-www-form-urlencoded'
					},
				    data: {uid:uid,id:that.goods[that.jb_index].id,cause:that.yuanyin,type:1},
				    success: (res) => {
						uni.hideLoading();
						if(res.data.code!=1){
							uni.showToast({
							    title: res.data.msg,
								icon:'none',
							    duration: 1500
							});
							return false;
						}
						that.jbclose();
						uni.showToast({
						    title: res.data.msg,
							icon:'success',
						    duration: 1500
						});
				    }
				});
			},
			cause: function(event) {
			    this.yuanyin = event.target.value
			},
			pai(e){
				this.px_index = e.target.value;
				this.page=1;
				this.next=0;
				this.laoshi(1);
			},
			xingbie(e){
				this.sex_index = e.target.value;
				this.page=1;
				this.next=0;
				this.laoshi(1);
			},
			jiguan(e){
				this.sheng_index = e.target.value;
				this.page=1;
				this.next=0;
				this.laoshi(1);
			},
			yuanxiao(e){
				this.school_index = e.target.value;
				this.page=1;
				this.next=0;
				this.laoshi(1);
			},
			xshaixuan(){
				this.is_xk=!this.is_xk;
			},
			lei(e){
				var p=e.currentTarget.dataset.id;
				
				this.cid=p;
				if(p==0){
					this.cid2=-1;
					this.xueke2=[];
				}
				if(e.currentTarget.dataset.type==1){
					var index=e.currentTarget.dataset.index;
					this.xueke2=this.xueke[index].xueke;
					return false;
				}
				this.is_xk=false;
				this.page=1;
				this.next=0;
				if(p>0){
				this.cid2=0;
				}
				this.laoshi(1);
			},
			lei2(e){
				var p=e.currentTarget.dataset.id;
				this.cid2=p;
				this.is_xk=false;
				this.page=1;
				this.next=0;
				this.laoshi(1);
			},
			img(e){
				var gid=e.currentTarget.dataset.gid;
				if(gid>0){
					uni.navigateTo({
					    url: '/pages/goods/detail?id='+gid
					});
				}
			},
			sousuo(event){
				if(app.isBlank(event.target.value)==true){
					uni.showToast({
					    title: "请输入关键词",
						icon:'none',
					    duration: 1000
					});
					return false;
				}
				this.keyword2=event.target.value;
				this.keyword=event.target.value;
				this.page=1;
				this.next=0;
				this.laoshi(1);
			},
			key(event){
				this.keyword=event.target.value;
			},
			sou(){
				if(app.isBlank(this.keyword)==true){
					uni.showToast({
					    title: "请输入关键词",
						icon:'none',
					    duration: 1000
					});
					return false;
				}
				this.keyword2=this.keyword;
				this.page=1;
				this.next=0;
				this.laoshi(1);
			},
			xiao(){
				uni.navigateTo({
				    url: '/pages/news/index'
				});
			},
			gurl(e){
				var id=e.currentTarget.dataset.id;
				uni.navigateTo({
				    url: '/pages/teacher/detail?id='+id
				});
			},
			onPageScroll(e){
				/*if(e.scrollTop>=500){
					this.is_pf=1;
				}else{
					this.is_pf=0;
				}*/
			},
			onReachBottom(){
				if(this.next==1){
					this.next=0;
					this.laoshi();
				}
			}
		}
	}
</script>

<style>
	.jubaocause4-2{width:100px;height:35px;line-height: 35px;background-color: #05c160;color:#fff;text-align: center;float: right;margin-top: 14px;border-radius: 3px;}
	.jubaocause4-1{width:100px;height:35px;line-height: 35px;background-color: #ccc;color:#fff;text-align: center;float: left;margin-top: 14px;border-radius: 3px;}
	.jubaocause4{width:90%;margin: 0 auto;height:50px;overflow: hidden;}
	.jubaocause3 textarea{width:94%;height:140px;font-size: 0.85rem;color:#333;line-height: 24px;padding: 5px 3%;}
	.jubaocause3{width:90%;height:150px;background-color: #f8f8f8;border-radius: 3px;margin: 0 auto;}
	.jubaocause2 image{width:20px;height:20px;float: right;margin-top: 10px;}
	.jubaocause2 text{font-weight: 550;}
	.jubaocause2{width:90%;margin: 0 auto;height:40px;overflow: hidden;line-height: 40px;}
	.jubaocause{width:300px;height:250px;position: fixed;top:50%;margin-top: -125px;left:50%;margin-left: -150px;background-color: #fff;z-index: 9999;border-radius: 5px;}
	
	
	.top4 text{float: left;font-size: 0.75rem;}
	.top4 image{width:12px;height:12px;margin-top: 10px;float: left;}
	.top4{display: inline-block;height:30px;line-height: 30px;margin: 0 auto;}
	.top33{width:20%;height:30px;float: left;text-align: center;}
	.top22{width:100%;height:30px;overflow: hidden;padding-top: 5px;border-bottom: 1px #eee solid;padding-bottom: 5px;}
	.top222{width:100%;height:30px;overflow: hidden;padding-top: 5px;border-bottom: 1px #eee solid;padding-bottom: 5px;position: fixed;top:0px;z-index: 9999;background-color: #fff;}
	
	.gonggao{width:94%;padding: 5px 3%;overflow: hidden;}
	.laba{width:10%;float: left;height:24px;}
	.laba image{width:18px;margin-top: 3px;}
	
	.gonggao_nei{width:75%;height:24px;line-height: 24px;color:#d43030;overflow: hidden;font-size: 0.8rem;float: left;}
	.swiper2 {
	  width: 100%;
	  height:24px;
	}
	.gonggao_title{width:100%;height:24px;line-height: 24px;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;color:#d43030;}
	.gonggao_gengduo{width:15%;float: right;}
	.gonggao_gengduo_1{width:35px;height:18px;line-height: 18px;background-color: #d43030;text-align: center;font-size: 0.6rem;color:#fff;border-radius: 5px;float: right;margin-top: 3px;}
	
	.map2{width:100%;height:20px;line-height: 20px;color:#666;overflow: hidden;flex: 1;}
	.map .map3{width:16px;height:16px;margin-top: 2px;margin-right: 5px;}
	
	.map{width:100%;display: flex;margin-top: 5px;}
	.goods6{width:100%;height:25px;line-height: 25px;color:#999;overflow: hidden;}
	.goods5{width:100%;height:25px;line-height: 25px;color:#999;overflow: hidden;}
	.goods44{width:100%;overflow: hidden;}
	.goods4-9{width:100%;height:25px;line-height: 25px;color:#666;overflow: hidden;}
	.goods4-8 text{color:#666;font-size: 0.8rem;}
	.goods4-8{width:100%;height:25px;line-height: 25px;overflow: hidden;}
	.goods4-7{width:50%;height:25px;color:#05c160;float: left;overflow: hidden;line-height: 25px;}
	.goods4-6{color:#666;display: block;width:100%;height:25px;line-height: 25px;overflow: hidden;text-align: right;}
	.goods4-5{font-size: 0.9rem;color:#fe2424;display: block;width:100%;height:25px;line-height: 25px;overflow: hidden;text-align: right;}
	.goods4-0{width:100%;display: flex;}
	.goods4-4{width:50%;height:25px;float: left;color:#05c160;overflow: hidden;line-height: 25px;font-size: 0.75rem;font-weight: 550;}
	.map4{width:16px;height:16px;margin-top: 5px;margin-left: 5px;}
	.goods4-3-1{width:100%;height:25px;line-height: 25px;overflow: hidden;font-weight: 600;font-size: 1rem;flex:1;}
	.goods4-3{width:100%;display: flex;}
	.goods4-2{width:100%;height:100px;flex: 1;}
	.goods4-1{width:100px;height:100px;border-radius: 5px;margin-right: 10px;}
	.goods4{width:94%;padding: 10px 3%;border-bottom: 1px #eee solid;}
	.goods3{width:100%;}
	.goods2-2{font-size: 0.8rem;float: right;color:#999;}
	.goods2-1{font-size: 1rem;font-weight: 600;float: left;border-left: 5px #05c160 solid;padding-left: 8px;line-height: 18px;}
	.goods2{width:100%;height:18px;line-height: 18px;overflow: hidden;}
	.goods{width:100%;}
	.scroll-x{white-space: nowrap;display: flex;}
	scroll-view ::-webkit-scrollbar {width: 0;height: 0;background-color: transparent;}
	.nav2{height:32px;line-height:32px;padding: 0px 15px;font-size: 0.9rem;color:#333;display: inline-block;}
	.nav{width: 100%;height:35px;overflow: hidden;padding-bottom: 3px;background-color: #fff;}
	.empty{width:70%;margin: 30px auto;}
	.top2 input{width:88%;padding:0px 6%;height:30px;font-size: 0.85rem;}
	.top3{width:70px;height:28px;margin-left: 10px;text-align: center;line-height: 28px;color: #05c160;border:1px #05c160 solid;border-radius: 8px;}
	.top2{width:100%;height:30px;flex:1;background-color: #fff;border-radius: 20px;position: relative;}
	.top{width:94%;padding:0px 3%;display: flex;background-color: #ededed;padding-bottom:8px;padding-top: 8px;}
	.daohang{width:100%;overflow: hidden;margin-top: 5px;margin-bottom: 15px;}
	.daohang2{width:25%;float: left;text-align: center;margin-top: 10px;display: block;}
	.daohang2 image{width:40px;height:40px;}
	.dh_t{width:96%;padding: 0px 2%;height:20px;line-height: 20px;text-align: center;font-size: 0.8rem;overflow: hidden;}
	.swiper {
	  width: 100%;
	}
	.swiper image {
	  height: 100%;
	  width: 100%;
	}
	
	.dalei2-1{width:100%;height:20px;line-height: 20px;text-align: center;overflow: hidden;font-size: 0.8rem;}
	.dalei2 image{width:40px;height:40px;}
	.dalei2{width:25%;float: left;text-align: center;margin-top: 15px;}
	.dalei{width:100%;overflow: hidden;margin-bottom: 10px;}
	.zheceng5{width:100%;height:35px;line-height: 35px;text-align: center;position: absolute;bottom: 0px;background-color:#f6f6f6 ;}
	.zcactive{border-color: #05c160!important;background-color: #cff4e0!important;}
	.zheceng4-2-1:nth-child(3n+3){margin-right: 0px!important;}
	.zheceng4-2-1{width:31%;height:30px;line-height: 30px;border:1px #f6f6f6 solid;text-align: center;background-color: #f6f6f6;border-radius: 5px;margin-right: 2.2%;margin-bottom: 8px;float: left;overflow: hidden;font-size: 0.8rem;}
	.zheceng4-2{width:100%;overflow: hidden;margin-top: 5px;}
	.zheceng4-1{width:100%;height:25px;line-height: 25px;font-size: 0.9rem;font-weight: 600;}
	.zheceng4{width:94%;padding: 10px 3%;}
	.zheceng3{width:100%;height:40px;line-height: 40px;text-align: center;border-bottom: 1px #eee solid;}
	.zheceng2{width:300px;height:100vh;position: fixed;top:0px;right: 0px;background-color: #fff;z-index: 9999;}
	.zheceng{width:100%;height:100vh;position: fixed;top:0px;z-index: 9999;background-color: #000000;opacity: 0.7;}
	
	
	.news{width:94%;padding: 0px 3%;display: flex;margin-top: 10px;}
	.news2{width:36px;height:25px;margin-right: 5px;}
	.news3{width:26px;height:25px;float: left;}
	.news3 image{width:20px;height:20px;margin-top: 3px;}
	.news4{width:10px;height:25px;float: left;}
	.news4 view{width:1px;height:20px;margin: 0 auto;background-color: #999;margin-top: 2.5px;}
	
	.news_c{width:100%;flex:1;}
	.news_c2{width:100%;}
	.gg_c{width:100%;height:25px;line-height: 25px;color:#999;overflow: hidden;color: #333;font-size: 0.85rem;text-overflow: ellipsis;white-space: nowrap;}
	
</style>
